package LeetCode;

public class LC_108_ConvertSortedArraytoBinarySearchTree {
    public static void main(String[] args) {

    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            int low = 0;
            int high = nums.length - 1;
            return sortedArrayToBST(nums, low, high);
        }

        private TreeNode sortedArrayToBST(int[] nums, int low, int high) {
            TreeNode root = null;
            if (low <= high) {
                int mid = (low + high) / 2;
                root = new TreeNode(nums[mid]);
                root.left = sortedArrayToBST(nums, low, mid - 1);
                root.right = sortedArrayToBST(nums, mid + 1, high);
            }
            return root;
        }
    }
}